<template>
 <!--宽度350px,上下外边距180px,左右外边距等宽-->
<el-form ref="form" :rules="rules" :model="form" label-width="80px" class="loginContainer">
  <el-form-item label="用户名" prop="username">
    <!-- placeholder 属性规定可描述输入字段预期值的简短的提示信息 auto-complet 输入框自动提示完成功能-->
    <el-input v-model="form.username"  type="text" placeholder="请输入用户名" auto-complete="off"></el-input>
  </el-form-item>
  <el-form-item label="密  码" prop="password">
    <el-input v-model="form.password"  type="password" placeholder="请输入密码" auto-complete="off"></el-input>
  </el-form-item>
  <el-form-item>
    <el-button type="primary" @click="onSubmit(form)">登陆</el-button>
    <el-button @click="cancel(form)">取消</el-button>
  </el-form-item>
</el-form>
</template>
<script>
export default {
  data () {
    return {
      form: {
        username: '',
        password: ''
      },
      // 表单验证
      rules: {
        username: [
          {required: true, message: '请输入用户名称', trigger: 'blur'}
        ],
        password: [
          {required: true, message: '请输入密码', trigger: 'blur'}
        ]
      }
    }
  },
  methods: {
    onSubmit (formName) {
      console.log('submit!')
      // 连接后台，登陆成功后要跳转到首页,提交的时候登陆验证
      this.$refs[formName].validate(valid => {
        if (valid) {
          // 表单提交到后端验证登陆
          console.log('success!')
        } else {
          console.log('fail!')
        }
      })
    },
    cancel (formName) {
      console.log('submit!')
      // 连接后台，登陆成功后要跳转到首页,提交的时候登陆验证
      this.$refs[formName].validate(valid => {
        if (valid) {
          console.log('success!')
        } else {
          console.log('fail!')
        }
      })
    }

  }
}
</script>

<style>
  .loginContainer {
    width: 350px;
    margin: 180px auto;
  }
</style>
